<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redis;
use App\Model\Goods;
use App\Model\Goodsattr;
use App\Model\Goodspic;
use App\Model\Goodstype;
use App\Http\Controllers\Api\GoodsDetailSelect;

/**
 * 处理ajax的方法
 */
class GoodsDetailAjax extends Controller
{
    /**
     * 获取对应条件的尺寸
     * data $id $color
     * @return $sizedata
     */
    public function GetColorunderTheSize($id, $color)
    {
        // 获取对应条件的尺寸
        $sizedata = Goodsattr::select('size')
          ->where([
              ['goods_id', '=',$id],
              ['color', '=',$color],
          ])
          ->get()
          ->toArray();
        // 返回尺寸数组
        return $sizedata;
    }

    /**
     * 获取该尺寸商品的库存
     * data $id $size $color
     * @return $reserve
     */
    public function GetGoodsReserve($id, $size, $color)
    {
        // 获得该详情的库存
        $reserve = Goodsattr::select('reserve')
            ->where([
                ['goods_id', '=', $id],
                ['size', '=', $size],
                ['color', '=', $color],
            ])
            ->first()
            ->toArray();
        // 返回数据
        return $reserve;
    }

    /**
     * 获取该商品的id
     * data $id $size $color
     * @return $reserve
     */
    public function GetGoodsInfo($id, $size, $color)
    {
        // 获得该详情的库存
        $reserve = Goodsattr::select('id')
            ->where([
                ['goods_id', '=', $id],
                ['size', '=', $size],
                ['color', '=', $color],
            ])
            ->first()
            ->toArray();
        // 返回数据
        return $reserve;
    }

}
